package cn.itsource.timemessage;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;

import java.util.Date;

public class timeProducer {
    public static void main(String[] args) throws Exception {
        //1.创建生产者组
        DefaultMQProducer producer = new DefaultMQProducer("producer-hello");
        //2.设置NameServer地址
        producer.setNamesrvAddr("127.0.0.1:9876");

        //3.启动producer实例
        producer.start();

        //4.创建消息
        Message message = new Message("log-topic", "info-tag", "这是一个info5信息".getBytes(RemotingHelper.DEFAULT_CHARSET));
        System.out.println("发送时间:"+new Date().toLocaleString());
        // 设置延时等级3,这个消息将在10s之后发送(现在只支持固定的几个时间,详看delayTimeLevel)
        message.setDelayTimeLevel(4);
        //5.发送消息
        SendResult result = producer.send(message);
        //6.关闭producer实例
        producer.shutdown();

        System.out.println("发送完毕，结果: " + result);
    }
}
